package UseCollection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.function.Consumer;

public class CollectionBianLi {
    public static void main(String[] args) {
        Collection<String> coll= new ArrayList<>();
        coll.add("小平");
        coll.add("喜欢");
        coll.add("那个东西");
        // IteratorMethod(coll);
        // forMethod(coll);
        lambdaMethod(coll);
    }
    // 迭代器遍历
    public static void IteratorMethod(Collection<String> coll){
        Iterator<String> it = coll.iterator();
        while (it.hasNext()){
            String str = it.next();
            System.out.println(str);
        }
    }
    // 增强for循环
    public static void forMethod(Collection<String> coll){
        for (String o : coll) {
            System.out.println(o);
        }
    }
    // lambda表达式操作
    public static void lambdaMethod(Collection<String> coll){
        // 匿名类
        coll.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });
        // lambda表达式
        coll.forEach(s -> System.out.println(s));
    }
}
